<!--
 * @Author: your name 监测点信息
 * @Date: 2021-12-29 21:52:08
 * @LastEditTime: 2022-01-05 14:52:42
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \am-ui\src\pages\am\monitor\PointInfo.vue
-->
<template>
  <div>
    <el-row>
      <el-col
        :span="7"
        style="padding-right: 0.5em; border-right: 1px solid #b9b7b7"
      >
        <div class="btns">
          <el-input
            v-model="filterText"
            placeholder="请输入工程关键字"
            clearable
          ></el-input>
        </div>

        <el-tree
          :data="edTree"
          :props="props"
          @node-click="handleNodeClick"
          :filter-node-method="filterNode"
          ref="tree"
        ></el-tree>
      </el-col>
      <el-col :span="17">
        <div v-if="params.device_id">
          <div class="right_header">
            <i class="el-icon-s-goods"></i> 工程信息
          </div>
          <div class="engineer">
            <el-form>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="工程编号:">
                    {{ device.engineer.serial_number }}
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="工程名称:">
                    {{ device.engineer.name }}
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="工程类型:">
                    {{ device.engineer.type }}
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="工程状态:">
                    <el-tag
                      size="small"
                      v-if="device.engineer.status == '已结束'"
                      type="info"
                      >已结束</el-tag
                    >
                    <el-tag
                      size="small"
                      v-if="device.engineer.status == '未绑定'"
                      type="danger"
                      >未绑定</el-tag
                    >
                    <el-tag
                      size="small"
                      v-if="device.engineer.status == '监测中'"
                      type="success"
                      >监测中</el-tag
                    >
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="开始时间:">
                    <div v-if="device.engineer.begin_time == null">
                      暂未完成
                    </div>
                    <div v-else>
                      {{ device.engineer.begin_time | fmtTime }}
                    </div>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="结束时间:">
                    <div v-if="device.engineer.end_time == null">暂未完成</div>
                    <div v-else>
                      {{ device.engineer.end_time | fmtTime }}
                    </div>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="地址:">
                    {{ device.engineer.address }}
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="工程负责人:">
                    <div v-if="device.engineer.charge_name == null">暂无</div>
                    <div v-else>{{ device.engineer.charge_name }}</div>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </div>

          <div class="right_header">
            <i class="el-icon-s-tools"></i> 设备信息
          </div>
          <div class="device">
            <el-form>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="工程设备:">
                    {{ device.serial_number }}
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="设备名称:">
                    {{ device.name }}
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="绑定状态:">
                    <el-tag
                      size="small"
                      v-if="device.bind_status == 0"
                      type="danger"
                      >未绑定</el-tag
                    >
                    <el-tag size="small" v-else type="success">已绑定</el-tag>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="在线状态:">
                    <el-tag
                      size="small"
                      v-if="device.online_status == 0"
                      type="danger"
                      >离线</el-tag
                    >
                    <el-tag size="small" v-else type="success">在线</el-tag>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </div>
        </div>
        <div
          v-else
          style="
            line-height: 500px;
            color: #999;
            font-size: 30px;
            text-align: center;
          "
        >
          请选择设备
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { get } from "@/utils/request";
export default {
  // 变量
  data() {
    return {
      props: {
        value: "id",
        label: "name",
      },
      edTree: [],
      params: {
        page: 1,
        pageSize: 100,
      },
      form: {},
      device: {
        engineer: {},
      },
      filterText: "",
    };
  },
  //监测搜索框的值是否变化
  watch: {
    filterText(val) {
      this.$refs.tree.filter(val);
    },
  },
  // 方法
  methods: {
    //模糊搜索
    filterNode(value, edTree) {
      if (!value) {
        return true;
      } else {
        return edTree.name.indexOf(value) !== -1;
      }
    },
    // 树形节点点击事件
    handleNodeClick(node) {
      // 判断用户点击的是否是设备，点击工程时不查询信息
      if (node.engineer_id) {
        // 点击了设备
        this.$set(this.params, "engineer_id", node.engineer_id);
        this.$set(this.params, "device_id", node.id);

        // 调用设备信息
        this.loadDeviceDetails();
      }
    },
    // 查询工程设备树
    findEngineerDevices() {
      get("/engineer/findEngineerDeviceTree", this.params).then((res) => {
        this.edTree = res.data;
      });
    },
    //查询设备信息
    loadDeviceDetails() {
      get("/device/findDeviceDetail", { id: this.params.device_id }).then(
        (res) => {
          this.device = res.data;
        }
      );
    },
  },
  // 页面加载完毕后执行
  created() {
    // 查询工程设备树
    this.findEngineerDevices();
  },
};
</script>
<style scoped>
.engineer {
  padding: 0 0 10px 50px;
}
.device {
  padding: 0 0 10px 50px;
}
.right_header {
  height: 42px;
  line-height: 42px;
  background: #ededed;
  color: rgb(100, 99, 99);
  font-size: 18px;
  border-radius: 3px;
  padding-left: 1em;
  margin: 0 5px 20px 5px;
}
</style>